#include<ros/ros.h>
#include<turtlesim/Spawn.h>

//client端 为turtlesim_node 生成一个新的海龟（服务端程序由turtlesim提供）
int main(int argc, char** argv){
    ros::init(argc, argv,"spawn_turtle");
    ros::NodeHandle nh;

    ros::ServiceClient spawnClient = nh.serviceClient<turtlesim::Spawn>("spawn");

    turtlesim::Spawn::Request req;
    turtlesim::Spawn::Response res;

    req.x=2;
    req.y=3;
    req.theta=M_PI/2;
    req.name="hc";
    //请求服务spawn
    bool success = spawnClient.call(req, res);

    if(success){
        ROS_INFO_STREAM("spawned a turtle named "<<res.name);
    }else{
        ROS_INFO_STREAM("failed to spawn");
    }
}